﻿// -----------------------------------------------------------------------
// <copyright file="MyVideoSpriteBatch.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using ObjectLibrary;
namespace _0912089_0912172
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class My2DVideo : VisibleGameEntity2D
    {
        Rectangle _screenRect;     
        protected Video video;
        protected VideoPlayer videoPlayer;
        protected bool flag = true;

        public void Play()
        {
            if (videoPlayer.State != MediaState.Playing && flag)
            {
                videoPlayer.Play(video);
                flag = false;
            }
        }

        public bool isStop()
        {
            return (videoPlayer.State == MediaState.Stopped && !flag);
        }

        public void Stop()
        {
            if (videoPlayer.State != MediaState.Stopped)
            {
                videoPlayer.Stop();
            }
        }
        public My2DVideo(ContentManager content, string videoName, Rectangle screenRect)
        {
            videoPlayer = new VideoPlayer();
            video = content.Load<Video>(videoName);
            _screenRect = screenRect;
        }

        public override void Update(GameTime gameTime)
        {
            if (videoPlayer.State == MediaState.Playing)
            {
                _texture = videoPlayer.GetTexture();
            }
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch )
        {
            spriteBatch.Draw(_texture, _screenRect, new Rectangle(0, 0, _texture.Width, _texture.Height), Color.White);
        }
    }
}
